<template>
  <div class="home" :style="{ 'min-height': minHeight }">
    <van-nav-bar title="新增地址" left-arrow>
      <template #left>
        <Back></Back>
      </template>
    </van-nav-bar>
    <van-address-edit
      :area-list="areaList"
      show-postal
      show-set-default
      show-search-result
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave($event)"
    />
  </div>
</template>

<script>
import Back from "../components/Back.vue";
import { areaList } from "@vant/area-data";
export default {
  name: "NewAddress",
  data() {
    return {
      minHeight: innerHeight + "px",
      tokenString: sessionStorage.getItem("userToken"),
      appkey: "U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=",
      areaList,
    };
  },
  methods: {
    onSave(e) {
      //   
      //   
      let obj = {};
      obj.appkey = this.appkey;
      obj.tokenString = this.tokenString;
      obj.name = e.name;
      obj.tel = e.tel;
      obj.province = e.province;
      obj.city = e.city;
      obj.county = e.county;
      obj.addressDetail = e.addressDetail;
      obj.areaCode = e.areaCode;
      obj.postalCode = e.postalCode;
      obj.isDefault = e.isDefault ? 1 : 0;
      let data = "";
      for (let key in obj) {
        data += `${key}=${obj[key]}&`;
      }
      data = data.slice(0, -1);
      
      this.axios({
        method: "post",
        url: "http://www.kangliuyong.com:10002/addAddress",
        data,
      })
        .then((res) => {
          
          this.$router.go(-1);
        })
        .catch((err) => {
          
        });
    },
  },
  components: {
    Back,
  },
};
</script>

<style lang="less" scoped>
.home {
  background-color: rgb(245, 245, 245);
}
/deep/.van-button--danger {
  background-color: rgb(12, 52, 186);
  border: 1px solid rgb(12, 52, 186);
}
</style>